<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>报价协议管理</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //
        <!--业务编码、集装箱号、合同协议号、提运单号、进出口类型、收发货人、供应商、下单人-->
        var pickUpDateLayerId = 0;
        var editViewLayerId = 1;
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [{
                name: "supplierId",
                label: "业务供应商",
                type: "dropdown",
                dropdownType: "ajax",
                url: "<s:url value='/order-dropdown/supCompany'/>",
                op: "eq",
                minLength: 0,
                keyWordName: "key",
                success: function (data) {
                    data = data.results;
                    var array = new Array();
                    $.each(data, function (i, n) {
                        array.push([n["name"], n["value"]]);
                    });
                    return array;
                }
            },{
                name: "bizType",
                label: "业务类型",
                type: "dropdown",
                dropdownType: "ajax",
                url: "<s:url value='/api/dictionary/getJsonByCodes?codes='/>" + encodeURI("{'codes':['protocol_biz_type']}"),
                op: "eq",
                minLength: 0,
                keyWordName: "key",
                success: function (data) {
                    data = data.content[0].protocol_biz_type;
                    var array = new Array();
                    $.each(data, function (i, n) {
                        array.push([n["dtName"], n["dtId"]]);
                    });
                    return array;
                }
            }, {
                name: "feeType",
                label: "费用类型",
                type: "dropdown",
                dropdownType: "ajax",
                url: "<s:url value='/api/dictionary/getJsonByCodes?codes='/>" + encodeURI("{'codes':['protocol_fee_type']}"),
                op: "eq",
                minLength: 0,
                keyWordName: "key",
                success: function (data) {
                    var array = [];
                    var contentData = data.content[0];
                    for (var ky in contentData) {
                        var sdata = contentData[ky];
                        $.each(sdata, function (i, n) {
                            array.push([n["dtName"], n["dtId"]]);
                        });
                    }
                    return array;
                }
            }, {
                name: "countRule",
                label: "计算规则",
                type: "dropdown",
                dropdownType: "ajax",
                url: "<s:url value='/api/dictionary/getJsonByCodes?codes='/>" + encodeURI("{'codes':['protocol_count_fee_rule']}"),
                op: "eq",
                minLength: 0,
                keyWordName: "key",
                success: function (data) {
                    var array = [];
                    for (var i = 0; i < data.content.length; i++) {
                        var contentData = data.content[i];
                        for (var ky in contentData) {
                            var sdata = contentData[ky];
                            $.each(sdata, function (i, n) {
                                array.push([n["dtName"], n["dtId"]]);
                            });
                        }
                    }
                    return array;
                }
            }, {
                    name: "ieType",
                    label: "进出口类型",
                    type: "dropdown",
                    data: [["进口", "imp"], ["出口", "exp"]],
                    op: "eq",
                    minLength: 0
                }],
            buttons: {
                custom: [{
                    id: "addQtPrice",
                    value: "添加报价",
                    index: 1,
                    click: function () {
                        editViewLayerId = layer.open({
                                       type: 2,
                                       title: false,
                                       content: 'editView',
                                       area: ['840px', '400px'],
                                       success: function (layero, index) {
                                           var $layer0 = $(layero[0]);
                                           var layerIframeBodyHeight = $($layer0.find(
                                               'iframe')[0].contentDocument.body).height();
                                           $layer0.height(layerIframeBodyHeight + 60, 2000);
                                       }
                                   });
                    }
                }, {
                    id: "edit",
                    value: "编辑报价",
                    index: 2,
                    click: function () {
                        var selId = $("#protocolGrid").gridMethods().getId();
                        if (!selId) {
                            layer.msg("请先选择一行");
                            return;
                        }
                        editViewLayerId = layer.open({
                                       type: 2,
                                       title: false,
                                       content: 'editView?id=' + selId,
                                       area: ['840px', '320px'],
                                       success: function (layero, index) {
                                           var $layer0 = $(layero[0]);
                                           var layerIframeBodyHeight = $($layer0.find(
                                               'iframe')[0].contentDocument.body).height();
//                                           $layer0.height(layerIframeBodyHeight + 100, 1000);
                                       }
                                   });
                    }
                }, {
                    id: "sendProtocol",
                    value: "发往确认",
                    index: 2,
                    click: function () {
                        var selRows = $("#protocolGrid").gridMethods().getSelectRows();
                        if (selRows.length === 0) {
                            layer.msg("请先选择一行");
                            return;
                        }
                        pickUpDateLayerId = layer.open({
                                       type: 1,
                                       title: false,
                                       content: $('#pickDate'),
                                       area: ['640px', '150px'],
                                       success: function (layero, index) {
                                       }
                                   });
                    }
                }, {
                    id: "chargingTest",
                    value: "测试用",
                    index: 3,
                    click: function () {
                        layer.open({
                               type: 2,
                               title:"询价、成本测试",
                               maxmin:true,
                               shade:false,
                               content: '<s:url value="/fund/protocol/test"/>',
                               area: ['1080px', '640px']
                           });
                    }
                }]
            },
            grid: {
                id: "protocolGrid",
                title: "查询结果",
                url: "viewData",
                multiselect: true,
                colModel: [{
                    index: "id",
                    name: "id",
                    hidden: true
                }, {
                    name: "supplierName",
                    label: "供应商"
                }, {
                    name: "feeType",
                    label: "费用类型",
                    align: 'center'
                }, {
                    name: "bizType",
                    label: "业务类型",
                    align: 'center'
                }, {
                    name: "ieType",
                    label: "进出口",
                    align: 'center'
                }, {
                    name: "name",
                    label: "费用名称",
                    align: 'center'
                }, {
                    name: "countRule",
                    label: "计费规则",
                    align: 'center'
                }, {
                    name: "startCount",
                    label: "起算数量",
                    align: 'center'
                },
//                 {
//                    name: "startPriceIn",
//                    label: "报价",
//                    align: 'center'
//                }, {
//                    name: "startPriceOut",
//                    label: "成本",
//                    align: 'center'
//                },
                {
                    name: "unitPriceIn",
                    label: "报价",
                    align: 'center'
                }, {
                    name: "unitPriceOut",
                    label: "成本",
                    align: 'center'
                }, {
                    name: "capPriceIn",
                    label: "报价",
                    align: 'center'
                }, {
                    name: "capPriceOut",
                    label: "成本",
                    align: 'center'
                }, {
                    name: "effectiveTime",
                    label: "生效时间"
                }, {
                    name: "descript",
                    label: "描述"
                }, {
                    name: "status",
                    label: "状态",
                    align: 'center'
                }],
                gridComplete:function () {
                    var $firstTh = $($("th[role=columnheader]")[0]);
                    $firstTh.width(24);
                    $firstTh.css("padding", 0);

                    var thead = $(".jqg-third-row-header");
                    var ths = thead.find("th");

                    var firstTr = $(".ui-row-ltr:first");
                    var tds = firstTr.find("td");

                    for (var i = 0; i < ths.length; i++) {
                        var th = ths[i];
                        var td = tds[i];
                        $(td).width($(th).width);
                    }
                }
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            jQuery("#protocolGrid").jqGrid('setGroupHeaders', {
                useColSpanStyle: false,
                groupHeaders: [
//                    {
//                        startColumnName: 'startPriceIn',
//                        numberOfColumns: 2,
//                        titleText: '<em>起步价</em>'
//                    },
                    {startColumnName: 'unitPriceIn', numberOfColumns: 2, titleText: '<em>单价</em>'},
                    {startColumnName: 'capPriceIn', numberOfColumns: 2, titleText: '<em>封顶价</em>'}
                ]
            });
            $("#startDateInput").datepicker({
                        dateFormat: "yy-mm-dd",
                        showAnim: "slideDown"
                    });
            $("#endDateInput").datepicker({
                  dateFormat: "yy-mm-dd",
                  showAnim: "slideDown"
              });
            $("#didPickedDate").click(function(){
                $("#didPickedDate").attr("disabled", "disabled");
                var protocolIds = [];
                var selRows = $("#protocolGrid").gridMethods().getSelectRows();
                for (var i = 0; i < selRows.length; i++) {
                    var selRow = selRows[i];
                    protocolIds.push(selRow.id);
                }
                var startDate = $("#startDateInput").val();
                var endDate = $("#endDateInput").val();
                $.ajax({
                       url:'<s:url value="/fund/protocol/biz/sendPtsToSup"/>',
                       method:'post',
                       dataType:'json',
                       data:{protocolIds:protocolIds.join(","), start: startDate, end : endDate},
                       success:function (data) {
                           layer.close(pickUpDateLayerId);
                           layer.msg(data.msg);
                       },
                       complete:function(){
                           $("#didPickedDate").removeAttr("disabled");
                       }
                })
            });
        });

        function reloadGridData(){
            $("#protocolGrid").gridMethods().reload();
        }

        function closeEditView(){
            layer.close(editViewLayerId);
        }
    </script>
</head>
<body>
<div id="table"></div>
<div id="pickDate" class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all" style="display: none">
    <fieldset id="mf_container0"
              class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
        <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
            <a href="javascript:void(0)"
               class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button">
                <span class="ui-icon ui-icon-circle-triangle-s"></span> </a>
            <span class="replace-ui-jqgrid-title">选择有效期</span></div>
        <table id="mf_table0" class="mrdTable" style="width: 100%;">
            <tbody>
            <tr>
                <td id="td_label_12" align="right" valign="middle"
                    style="width: 100px; height: 30px;">
                    <label>有效时间起：</label></td>
                <td id="td_control_12" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input id="startDateInput" name="start"
                                                               value="" type="text"
                                                               style="width: 98%;"></td>
                <td id="td_label_13" align="right" valign="middle"
                    style="width: 100px; height: 30px;">
                    <label>有效时间止：</label></td>
                <td id="td_control_13" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input id="endDateInput" name="end"
                                                               value="" type="text"
                                                               style="width: 98%;"></td>
            </tr>
            <tr class="mrdBtnTr">
                <td id="mf_buttons_container" colspan="6" align="right">
                    <input type="button"
                                       id="didPickedDate"
                                       class="ui-button ui-widget ui-state-default ui-corner-all"
                                       role="button"
                                       aria-disabled="false"
                                       value="发往确认"
                                       style="margin: 3px; font-size: 12px;">
                </td>
            </tr>
            </tbody>
        </table>
    </fieldset>
</div>
</body>
</html>
